package com.jijs.ws.handler;

import java.util.Iterator;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class LicenseHandler implements SOAPHandler<SOAPMessageContext>{

	@Override
	public boolean handleMessage(SOAPMessageContext context) {
		try {
			Boolean out = (Boolean) context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY);
			if(!out){
				SOAPEnvelope enve = context.getMessage().getSOAPPart().getEnvelope();
				SOAPHeader header = enve.getHeader();
				if(header==null){
					return false;
				}
				Iterator<SOAPHeaderElement> it = header.getChildElements();
				while(it.hasNext()){
					SOAPHeaderElement ele = it.next();
					if(ele.getLocalName().equals("licenseInfo")){
						System.out.println(ele.getTextContent());
					}
				}
			}
		} catch (SOAPException e) {
		}
		return false;
	}

	@Override
	public boolean handleFault(SOAPMessageContext context) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void close(MessageContext context) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Set<QName> getHeaders() {
		// TODO Auto-generated method stub
		return null;
	}

}
